#!/bin/Rscript

#>>>>>>>>>> Analise de custo 100 usuarios
#postscript(file="custos_100.eps", paper="special",width=10,height=10, horizontal=FALSE)
jpeg("custos_100.jpg")
par(mfrow=c(2, 3))

reserved <- c(1:70)
ondemand <- c(1:70)
receipt <- c(1:70)

#fee <- read.table("op_100_10/profits.dat")$V3
#data <- read.table("op_100_10/consumption.dat")
#fee <- read.table("op_partial_100_10/profits.dat")$V3
#data <- read.table("op_partial_100_10/consumption.dat")

#RF heuristic
fee <- read.table("rf/profits.dat")$V3
data <- read.table("rf/consumption.dat")

#Total reserved hrs
initial <- 1
end <- 12
for (i in 1:70) {
	reserved[i] <- sum(as.numeric(data[initial:end, 1121] + data[initial:end, 1126] + data[initial:end, 1131] + data[initial:end, 1147] + data[initial:end, 1152] + + data[initial:end, 1157] + + data[initial:end, 1173] + data[initial:end, 1178] + data[initial:end, 1183]))
	receipt[i] <- sum(as.numeric(data[initial:end, 3]))
	initial = initial + 12
	end = end + 12
}

#Total on-demand hrs
initial <- 1
end <- 12
for (i in 1:70) {
	ondemand[i] <- sum(as.numeric(data[initial:end, 1119] + data[initial:end, 1124] + data[initial:end, 1129] + data[initial:end, 1145] + data[initial:end, 1150] + data[initial:end, 1155] + data[initial:end, 1171] + data[initial:end, 1176] + data[initial:end, 1181]))
	initial = initial + 12
	end = end + 12
}

plot(receipt - (reserved+fee) - ondemand, col="green", type="l", xlab="Repetições", ylab="Valores Monetarios Anuais", main="op_100", ylim=c(0, 200000))
lines(receipt, col="blue")
lines(reserved+fee, col="red")
lines(ondemand, col="black")

#On-demand heuristic
fee <- read.table("on/profits.dat")$V3
data <- read.table("on/consumption.dat")

#Total reserved hrs
initial <- 1
end <- 12
for (i in 1:70) {
	reserved[i] <- sum(as.numeric(data[initial:end, 1121] + data[initial:end, 1126] + data[initial:end, 1131] + data[initial:end, 1147] + data[initial:end, 1152] + + data[initial:end, 1157] + + data[initial:end, 1173] + data[initial:end, 1178] + data[initial:end, 1183]))
	receipt[i] <- sum(as.numeric(data[initial:end, 3]))
	initial = initial + 12
	end = end + 12
}

#Total on-demand hrs
initial <- 1
end <- 12
for (i in 1:70) {
	ondemand[i] <- sum(as.numeric(data[initial:end, 1119] + data[initial:end, 1124] + data[initial:end, 1129] + data[initial:end, 1145] + data[initial:end, 1150] + data[initial:end, 1155] + data[initial:end, 1171] + data[initial:end, 1176] + data[initial:end, 1181]))
	initial = initial + 12
	end = end + 12
}

plot(receipt - (reserved+fee) - ondemand, col="green", type="l", xlab="Repetições", ylab="Valores Monetarios Anuais", main="on_100", ylim=c(0, 200000))
lines(receipt, col="blue")
lines(reserved+fee, col="red")
lines(ondemand, col="black")

#UT heuristic
fee <- read.table("ut/profits.dat")$V3
data <- read.table("ut/consumption.dat")

#Total reserved hrs
initial <- 1
end <- 12
for (i in 1:70) {
	reserved[i] <- sum(as.numeric(data[initial:end, 1121] + data[initial:end, 1126] + data[initial:end, 1131] + data[initial:end, 1147] + data[initial:end, 1152] + + data[initial:end, 1157] + + data[initial:end, 1173] + data[initial:end, 1178] + data[initial:end, 1183]))
	receipt[i] <- sum(as.numeric(data[initial:end, 3]))
	initial = initial + 12
	end = end + 12
}

#Total on-demand hrs
initial <- 1
end <- 12
for (i in 1:70) {
	ondemand[i] <- sum(as.numeric(data[initial:end, 1119] + data[initial:end, 1124] + data[initial:end, 1129] + data[initial:end, 1145] + data[initial:end, 1150] + data[initial:end, 1155] + data[initial:end, 1171] + data[initial:end, 1176] + data[initial:end, 1181]))
	initial = initial + 12
	end = end + 12
}

plot(receipt - (reserved+fee) - ondemand, col="green", type="l", xlab="Repetições", ylab="Valores Monetarios Anuais", main="ut_100", ylim=c(0, 200000))
lines(receipt, col="blue")
lines(reserved+fee, col="red")
lines(ondemand, col="black")

#Iosup heuristic
fee <- read.table("iosup/profits.dat")$V3
data <- read.table("iosup/consumption.dat")

#Total reserved hrs
initial <- 1
end <- 12
for (i in 1:70) {
	reserved[i] <- sum(as.numeric(data[initial:end, 1121] + data[initial:end, 1126] + data[initial:end, 1131] + data[initial:end, 1147] + data[initial:end, 1152] + + data[initial:end, 1157] + + data[initial:end, 1173] + data[initial:end, 1178] + data[initial:end, 1183]))
	receipt[i] <- sum(as.numeric(data[initial:end, 3]))
	initial = initial + 12
	end = end + 12
}

#Total on-demand hrs
initial <- 1
end <- 12
for (i in 1:70) {
	ondemand[i] <- sum(as.numeric(data[initial:end, 1119] + data[initial:end, 1124] + data[initial:end, 1129] + data[initial:end, 1145] + data[initial:end, 1150] + data[initial:end, 1155] + data[initial:end, 1171] + data[initial:end, 1176] + data[initial:end, 1181]))
	initial = initial + 12
	end = end + 12
}

plot(receipt - (reserved+fee) - ondemand, col="green", type="l", xlab="Repetições", ylab="Valores Monetarios Anuais", main="iosup_100", ylim=c(0, 200000))
lines(receipt, col="blue")
lines(reserved+fee, col="red")
lines(ondemand, col="black")

#Super heuristic
fee <- read.table("super/profits.dat")$V3
data <- read.table("super/consumption.dat")

#Total reserved hrs
initial <- 1
end <- 12
for (i in 1:70) {
	reserved[i] <- sum(as.numeric(data[initial:end, 1121] + data[initial:end, 1126] + data[initial:end, 1131] + data[initial:end, 1147] + data[initial:end, 1152] + + data[initial:end, 1157] + + data[initial:end, 1173] + data[initial:end, 1178] + data[initial:end, 1183]))
	receipt[i] <- sum(as.numeric(data[initial:end, 3]))
	initial = initial + 12
	end = end + 12
}

#Total on-demand hrs
initial <- 1
end <- 12
for (i in 1:70) {
	ondemand[i] <- sum(as.numeric(data[initial:end, 1119] + data[initial:end, 1124] + data[initial:end, 1129] + data[initial:end, 1145] + data[initial:end, 1150] + data[initial:end, 1155] + data[initial:end, 1171] + data[initial:end, 1176] + data[initial:end, 1181]))
	initial = initial + 12
	end = end + 12
}

plot(receipt - (reserved+fee) - ondemand, col="green", type="l", xlab="Repetições", ylab="Valores Monetarios Anuais", main="super_100", ylim=c(0, 200000))
lines(receipt, col="blue")
lines(reserved+fee, col="red")
lines(ondemand, col="black")

dev.off()

